package kama;

import java.util.Scanner;

public class Test0106 {
}
class Main0106_1{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int length1 = scanner.nextInt();
        int length2 = scanner.nextInt();
        scanner.nextLine();

        int[][] graph = new int[length1][];
        for (int i = 0; i < length1; i++) {
            String[] s = scanner.nextLine().split(" ");
            graph[i] = new int[length2];
            for (int j = 0; j < length2; j++)
                graph[i][j] = Integer.parseInt(s[j]);
        }

        for (int i = 0; i < length1; i++) {
            for (int j = 0; j < length2; j++) {
                if (graph[i][j] == 1) {
                    System.out.println(dfs(i,j,graph));
                    return;
                }
            }
        }

    }

    public static int dfs(int i, int j, int[][] graph) {
        if (i<0||j<0||i>= graph.length||j>= graph[0].length||graph[i][j] == 0) return 1;
        int ans = 0;
        if (graph[i][j] != 2){
            graph[i][j] = 2;
            ans += dfs(i+1,j,graph);
            ans += dfs(i,j+1,graph);
            ans += dfs(i-1,j,graph);
            ans += dfs(i,j-1,graph);
        }

        return ans;
    }
}
